//
//  FYMainViewController.swift
//  Weibo
//
//  Created by 冯毅 on 16/8/8.
//  Copyright © 2016年 冯毅. All rights reserved.
//

import UIKit

class FYMainViewController: UITabBarController {

    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        let fyTabBar = FYTabBar()
        
        fyTabBar.composeButtonClosure = { [weak self] in
            //  进入发微博界面
            self?.pushComposeVC()
        }
        
        setValue(fyTabBar, forKey: "tabBar")
        
        addChildViewController(FYHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(FYMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(FYDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(FYProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
        
        
    }
    
    private func pushComposeVC() {
        let composeVC = FYComposeViewController()
        let nav = UINavigationController(rootViewController: composeVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    func addChildViewController(childController: UIViewController,imageName: String,title: String) {
        childController.tabBarItem.image = UIImage(named: imageName)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        
        childController.title = title

        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor .orangeColor()], forState: .Normal)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        let  nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
